'use strict';

const Sequelize = require('sequelize');
const sequelize = require('../util/sequelize');

var Message = sequelize.define('message', {
    userId: {
        type: Sequelize.STRING
    },
    userName: {
        type: Sequelize.STRING
    },
    userGender: {
        type: Sequelize.INTEGER
    },
    city: {
        type: Sequelize.STRING,
        allowNull: true,
    },
    province: {
        type: Sequelize.STRING,
        allowNull: true,
    },
    avatarUrl: {
        type: Sequelize.STRING,
        allowNull: true,
    },
    content: {
        type: Sequelize.TEXT
    },
    latitude: {
        type: Sequelize.DOUBLE,
        allowNull: true,
        defaultValue: null,
        validate: {
            min: -90,
            max: 90
        }
    },
    longitude: {
        type: Sequelize.DOUBLE,
        allowNull: true,
        defaultValue: null,
        validate: {
            min: -180,
            max: 180
        }
    },
    locationTitle: {
        type: Sequelize.STRING,
        allowNull: true
    },
    comment: {
        type: Sequelize.INTEGER,
        defaultValue: 0
    },
    likes: {
        type: Sequelize.INTEGER,
        defaultValue: 0
    },
    read: {
        type: Sequelize.INTEGER,
        defaultValue: 0
    },
    state: {
        type: Sequelize.INTEGER,
        defaultValue: 0
    }
});

Message.sync({
    force: false
});

module.exports = Message;